<!-- 左边菜单栏 -->
<template>
	<uni-drawer :visible="$store.state.isxsd" mode="left" @close="$store.state.isxsd=false">
		<view class="row pd pt60">
			<image :src="$store.state.userinfo.avatar" class="iserrtyse yj"></image>
			<view class="col pl30">
				<view class="cf fz36 pt15">
					{{$store.state.userinfo.nickname}}
				</view>
				<view class="fz28 z9 mt10">
					<uni-icons :size="16" class="cz" color="#bbb" type="map" />
					<text class="ml5">山东·济南</text>
				</view>
			</view>
		</view>
		<view class="mt100">
			<uni-list>
				<uni-list-item title="切换车辆" @tap="tiaozf('/pages/leftSideMenu/SwitchVehicle')" ></uni-list-item>
				<uni-list-item title="靠近车门解锁" :show-arrow="false"  :showSwitch="showSwitch" @tap="unlogks" @switchChange="geyneert" :switchChecked="switchChecked"></uni-list-item>
				<uni-list-item title="代客泊车" :show-arrow="false"  :showSwitch="showSwitchdk" @tap="unlogksdk" @switchChange="geyneertdk" :switchChecked="switchCheckeddk"></uni-list-item>
				<uni-list-item title="热车时长" @tap="tiaozf('/pages/leftSideMenu/SolutionAgainstPattern?type=1&id='+$store.state.cars.id+'&sid='+$store.state.cars.status_id)" ></uni-list-item>
				<uni-list-item title="解防模式" @tap="tiaozf('/pages/leftSideMenu/SolutionAgainstPattern?type=2&id='+$store.state.cars.id+'&sid='+$store.state.cars.status_id)" ></uni-list-item>
				<uni-list-item title="副钥匙" @tap="tiaozf('/pages/leftSideMenu/ViceKey?id='+$store.state.cars.id+'&devsn='+$store.state.cars.devsn)" v-if="$store.state.cars.type ==1"></uni-list-item>
				<!-- <uni-list-item title="电子围栏" @tap="tiaozf('/pages/leftSideMenu/ElectronicFencehtml')" ></uni-list-item> -->
				<uni-list-item title="行程报告" @tap="tiaozf('/pages/leftSideMenu/TripReport')" ></uni-list-item>
				<!-- <uni-list-item title="登录" @tap="tiaozf('/pages/user/LoginAndRegistration')" :showArrow="false"></uni-list-item> -->

			</uni-list>
		</view>
	</uni-drawer>
</template>
<script>
	import uniDrawer from '@/components/uni-drawer/uni-drawer.vue'
	export default {
		props: ['showLeft'],
		data() {
			return {
				switchChecked:true,
				showSwitch:true,
				switchCheckeddk:true,
				showSwitchdk:true,
				showfu:true
			}
		},
		components: {
			uniDrawer
		},
		onShow() {
			let autounlk= "autounlk"+this.$store.state.cars.id
			let locks = uni.getStorageSync(autounlk)
			console.log(autounlk);
			if(locks === false){
				this.switchChecked = false
			}else{
				this.switchChecked = true
			}
			// this.switchChecked = true
			this.carinfo = uni.getStorageSync('current')
			if(this.carinfo.data.type == 0){
				this.showfu = false
			}
			// uni.showToast({
			// 	title:'副钥匙'+this.carinfo.type,
			// 	icon:"none"
			// })
			console.log(this.carinfo);
		},
		methods: {
			tiaozf(url) {
				uni.navigateTo({
					url: url
				})
			},
			geyneert(e) {
				let th = this
				this.switchChecked = false
				this.showSwitch = false
				let autounlk= "autounlk"+th.$store.state.cars.id
				if (e.value) {
					uni.showModal({
						title:"操作提醒",
						content:'靠近车门解锁：打开APP且正常连接车辆后，即可实现靠近车门解锁',
						success(e) {
							th.showSwitch = true
							if (e.confirm) {
								th.duration(1)
								th.switchChecked = true
								 // th.sendCom("Cmd_Auto_Unlk");
								 uni.setStorageSync(autounlk,true)
								 console.log(th.switchChecked)
							} else {
								th.switchChecked = false
								 uni.setStorageSync(autounlk,false)
							}
							
						}
					})
				} else {
					th.showSwitch = true
					 uni.setStorageSync(autounlk,false)
				}
			},
			geyneertdk(e) {
				let th = this
				this.switchCheckeddk = false
				this.showSwitchdk = false
				let dkboche= "dkboche"+th.$store.state.cars.id
				if (e.value) {
					uni.showModal({
						title:"温馨提示",
						content:'当您由于时间或其他原因，需要他人帮您停车时，打开代客泊车模式可以帮助到您。打开代客泊车模式，当他人帮您停好车熄火，10S后车辆会自动锁好车门。',
						success(e) {
							th.showSwitchdk = true
							if (e.confirm) {
								// th.duration(1)
								th.switchCheckeddk = true
								 th.sendCom("Cmd_DKBC_Mode");
								 uni.setStorageSync(dkboche,true)
								 console.log(th.switchChecked)
							} else {
								th.switchCheckeddk = false
								 uni.setStorageSync(dkboche,false)
							}
						}
					})
				} else {
					th.showSwitchdk = true
					 uni.setStorageSync(autounlk,false)
				}
			},
			async duration(time){
				console.log(this.$store.state.cars);
				var params=""
				params.id=this.$store.state.cars.status_id 
				params.unlock=time
				var shichang=await this.get("/api/change/"+this.$store.state.cars.id,params,"PUT")
				if(time==1){
					this.switchChecked=true
				}else{
					this.switchChecked=false
				}				
			},
			unlogks(e){
				let autounlk= "autounlk"+this.$store.state.cars.id
				let times =  uni.getStorageSync(autounlk)
				// this.switchChecked = false
				
				this.duration(times)
				// console.log(e);
				// this.sendCom("Cmd_Auto_Unlk");
			}
		},
		mounted() {
			
		}
	}
</script>
<style scoped>
	.iserrtyse {
		width: 120upx;
		height: 120upx;
	}
</style>